package edu.cuc.akkaDay01.demo03;

import akka.actor.UntypedActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;

/**
 * Created by bingruiqi on 2017/9/10.
 */
public class Myworker extends UntypedActor {
    private final LoggingAdapter log = Logging.getLogger(getContext().system(),this);
    public  static  enum Msg{
        WORKING,DONE,CLOSE;
    }
    @Override
    public void onReceive(Object o) throws Exception {
        if (o.equals(Msg.WORKING)) {
            System.out.println("I am working");
        }
        if (o.equals(Msg.DONE)) {
            System.out.println("stopping work");
        }
        if (o.equals(Msg.CLOSE)) {
            System.out.println("I will shutdown");
            getSender().tell(Msg.CLOSE, getSelf());
            getContext().stop(getSelf());
        } else {
            unhandled(o);
        }
    }

    @Override
    public void preStart() throws Exception {
        System.out.println("my working is starting");
    }

    @Override
    public void postStop() throws Exception {
        System.out.println("my working is stopping");
    }
}
